package models

type goods struct {
		Goods_id string `gorm:"colunmn:goods_id"`
		Goods_name string `gorm:"column:goods_name"`
		Gc_id string `gorm:"column:gc_id"`
		Goods_number int64 `gorm:"column:goods_number"`
		Goods_price int64 `gorm:"column:goods_price"`
		Factory_id string `gorm:"column:factory_id"`
}

func GetAllgoods() (error, []goods, int64)  {
	var goodsdata []goods
	//page := goodsParam["page"].(int)
	//pageSize := goodsParam["limit"].(int)
	//searchText := goodsParam["searchText"].(string)
	var total int64
	err := db.Table("goods").Order("gc_id ASC").Count(&total).Find(&goodsdata).Error

	return err, goodsdata, total
}

func Addgoods() (error, goods) {

	//a.BindJSON(&injurydata)
	//injurydata.Is_del = false
	//injurydata.Update_username = "系统管理员"
	//injurydata.Update_time = time.Now()
	goodsdata := goods{"16","足球","3",200,169,"01"}
	err := db.Table("goods").Create(&goodsdata).Error
	return err, goodsdata
}

func Updategoods() (error, goods) {

	//a.BindJSON(&injurydata)
	//injurydata.Update_username = "系统管理员"
	//injurydata.Update_time = time.Now()
	goodsdata := goods{"16","羽毛球","3",300,10,"01"}
	err := db.Table("goods").Where("goods_id = ?", goodsdata.Goods_id).Updates(&goodsdata).Error
	return err, goodsdata
}

func Delgoods() error {
	id := "16"
	err := db.Table("goods").Where("goods_id = ?", id).Delete(goods{}).Error
	return err
}
